<template>
	<div>
		<el-dialog :visible.sync="dialogVisible" :show-close="false">
			<div slot="title"
				style="border-bottom: 1px solid #cbcbcb;display: flex;align-items: center;justify-content: space-between;padding-bottom: 15px;">
				<div style="font-size: 18px;color: #333;">审核</div>
				<i class="el-icon-close" style="cursor: pointer;" @click="close()"></i>
			</div>

			<div>
				<div class="el-form-item__label">申请信息</div>
				<el-descriptions class="margin-top" title="" :column="1" border>
					<el-descriptions-item>
						<template slot="label">
							申请人
						</template>
						{{info.applicationPeople}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							申请时间
						</template>
						{{updateTimeChange(info.createTime)}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							申请说明
						</template>
						{{info.applicationInstructions}}
					</el-descriptions-item>
				</el-descriptions>

				<el-form :model="form" :rules="rules" ref="form" style="padding-top: 20px;">
					<el-form-item label="是否通过" prop="status">
						<el-select v-model="form.status" placeholder="请选择">
							<el-option label="通过" value="2"></el-option>
							<el-option label="驳回" value="3"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item label="审核意见" prop="approvalOpinion">
						<el-input type="textarea" v-model="form.approvalOpinion" placeholder="请输入审核意见" maxlength="500"
							show-word-limit :rows="5"></el-input>
					</el-form-item>
				</el-form>
			</div>

			<div slot="footer" style="display: flex;justify-content: center;">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="submitForm()">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		postMyProductAudit
	} from "@/request/api/demand";
	export default {
		data() {
			return {
				dialogVisible: false,
				info: {},

				form: {
					"id": '', // 订单ID
					"orderId": "", // 订单编号
					"status": '', // 审核状态 1未审批，2审批通过，3驳回
					"approvalOpinion": "" // 审核意见
				},
				rules: {
					status: [{
						required: true,
						message: '请选择',
						trigger: 'blur'
					}, ],
				},
			};
		},
		methods: {
			open(info) {
				this.dialogVisible = true
				this.info = info
				this.form = {
					"id": '', // 订单ID
					"orderId": "", // 订单编号
					"status": '', // 审核状态 1未审批，2审批通过，3驳回
					"approvalOpinion": "" // 审核意见
				}
				this.form.id = info.id
				this.form.orderId = info.orderId
			},
			// 格式化时间
			updateTimeChange(val) {
				return this.$moment(val).format('YYYY-MM-DD')
			},

			// 关闭
			close() {
				this.dialogVisible = false
			},
			// 创建
			submitForm(val) {
				this.$refs.form.validate((valid) => {
					if (valid) {

						postMyProductAudit(this.form).then((res) => {

							if (res.data.code === 1) {
								this.$message({
									message: res.data.message,
									type: "success",
								});
								this.$emit('getNewList')
								this.dialogVisible = false

							} else {
								this.$message.error(res.data.message);
							}
						});
					} else {
						return false;
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	/* 适用于手机的样式 */
	@media (max-width: 767px) {
		/deep/.el-dialog {
			width: 95%;
		}
	}

	.form-label {
		margin-top: 10px;
		text-align: right;
		padding-right: 15px;
	}
</style>